<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>预约设置列表</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../css/oksub.css">
	<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
	<!--模糊搜索区域-->
	<div class="layui-row">
		<form class="layui-form layui-col-md12 ok-search">
			<input class="layui-input" placeholder="规则名称" autocomplete="off" name="search_name">
			<button class="layui-btn" lay-submit="" lay-filter="search">
				<i class="layui-icon layui-icon-search"></i>
			</button>
		</form>
	</div>
	<!--数据表格-->
	<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script>
	layui.use(["element", "table", "form", "okLayer", "okUtils", "okMock"], function () {
		let table = layui.table;
		let form = layui.form;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let okMock = layui.okMock;

		//关闭loading
		okLoading.close();

		//先获取用户当前页面权限，split用逗号隔开分割成数组
        var action = okUtils.action_data().split(',')
        //根据动作权限做成的展示和隐藏
		var default_toolbar = okUtils.action_show(action);

		let theTable = table.render({
			elem: "#tableId",
			url: okMock.api.reservation_set.list,
			limit: 10,
			page: true,
			toolbar: "#toolbarTpl",
			headers: { token: okUtils.get_token() },
			response: {
                statusCode: HTTP_OK	//返回的状态码，默认是0
            },
			cols: [[
				{field: "LAY_TABLE_INDEX",title: "序号",width: 60,align: "center",templet: '#zizeng'},
				{field: "name", title: "规则名称", width: 220},
				{field: "start_date", title: "开始日期", width: 110},
				{field: "end_date", title: "结束日期", width: 110},
				{field: "am_start_time", title: "上午开馆时间", width: 115},
				{field: "am_end_time", title: "上午闭馆时间", width: 115},
				{field: "pm_start_time", title: "下午开馆时间", width: 115},
				{field: "pm_end_time", title: "下午闭馆时间", width: 115},
				{field: "max_lead", title: "提前预约天数", width: 120},
				{field: "slot_length", title: "时间段长度", width: 100},
				{field: "max_capacity", title: "最大预约人数", width: 120},
				{field: "weekdays", title: "日常闭馆", width: 90},
				{field: "status", title: "是否生效", templet: "#statusTpl", width: 90},
				{title: "操作", width: 80, align: "center", templet: "#operationTpl",fixed: "right",}
			]],
			done: function (res, curr, count) {}
		});

		//监听搜索按钮点击事件
		form.on("submit(search)", function (data) {
			//重载表格，并传递搜索条件
			theTable.reload({
				where: data.field,
				page: {curr: 1}
			});
			return false;
		});

		table.on("toolbar(tableFilter)", function (obj) {
			switch (obj.event) {
				case "add":
					add();
					break;
				case "batchDel":
					batchDel();
					break;
			}
		});

		table.on("tool(tableFilter)", function (obj) {
			let data = obj.data;
			switch (obj.event) {
				case "edit":
					edit(data.id);
					break;
				case "del":
					del(data.id);
					break;
				case "detail":
					detail(data.id);
					break;
			}
		});

		function add() {
			okLayer.open("添加预约设置", "insert.html", "90%", "90%", null, function () {
				theTable.reload();
			})
		}

		function del(id) {
			okLayer.confirm("确定要删除吗？", function () {
				//发送ajax提交表单数据
				okUtils.ajax(okMock.api.reservation_set.delete, "post", {id: id}).done(function (response) {
					if (response.code == HTTP_OK) {
						//删除成功后，刷新表格
						okLayer.greenTickMsg(response.message, function () {
							theTable.reload();
						});
					} else {
						layer.msg(response.message, { icon: 2, time: 2000 });
					}
				}).fail(function (error) {});
			})
		}

		function edit(id) {
			okLayer.open("编辑预约设置", "update.html?id=" + id, "90%", "90%", null, function () {
				theTable.reload();
			})
		}

		function detail(id) {
			okLayer.open("详情", "detail.html?id=" + id, "90%", "90%", null, function () {
				theTable.reload();
			})
		}
	})
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl"></script>
<!-- 行工具栏模板 -->
<script type="text/html" id="statusTpl">
	{{#  if(d.status == 1){ }}
	<span>生效</span>
	{{#  } else if(d.status == 1) { }}
	<span>不生效</span>
	{{#  }  }}
</script>
<!-- 操作栏 -->
<script type="text/html" id="operationTpl"></script>

<!-- 排序+1 -->
<script type="text/html" id="zizeng">
    {{d.LAY_TABLE_INDEX + 1}}
</script>
</body>
</html>
